﻿<%@ WebHandler Language="C#" Class="hCustomerInfo" %>
using System;
using System.Web;
using System.Data;
using System.Collections.Generic;
using CommonLib;
using System.Web.SessionState;
using Entities.System;
using BLL.Basic;

public class hCustomerInfo : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        handle(context);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    
    private void handle(HttpContext context)
    {
        string action = context.Request.QueryString["action"];
        string result = string.Empty;
        int? pageSize = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageSize = Convert.ToInt32(context.Request["rows"]);
        int? pageNum = null;
        if (!string.IsNullOrEmpty(context.Request["rows"])) pageNum = Convert.ToInt32(context.Request["page"]);
        Dictionary<string, string> dicLike = new Dictionary<string, string>();
        Dictionary<string, string> dicEqual = new Dictionary<string, string>();
        Dictionary<string, string> dicIn = new Dictionary<string, string>();
        try
        {
            if (context.Session["user"] == null) throw new Exception("登录超时！");
            User user = context.Session["user"] as Entities.System.User;
            CustomerInfoBO bo = new CustomerInfoBO();
            switch (action)
            {
                case "get":

                    if (!string.IsNullOrEmpty(context.Request["sSALESUSER"]))
                    {
                        string saleUser_keys = context.Request["sSALESUSER"].Trim();
                        if (saleUser_keys.EndsWith(","))
                            saleUser_keys = saleUser_keys.Substring(0, fac_keys.Length - 1);
                        dicIn.Add("t.SALES_USER_KEY", saleUser_keys);
                    }
                    if (!string.IsNullOrEmpty(context.Request["sSALESUSER[]"]))
                    {
                        string SaleUserKeys = context.Request["sSALESUSER[]"].Trim();
                        string saleUserkey = "";
                        string[] ArrSaleUserKeys = SaleUserKeys.Split(',');
                        for (int i = 0; i < ArrSaleUserKeys.Length; i++)
                        {
                            string s = ArrSaleUserKeys[i].Trim();
                            if (s == "") continue;
                            saleUserkey += s + ",";
                        }
                        if (saleUserkey.EndsWith(","))
                            saleUserkey = saleUserkey.Substring(0, fackey.Length - 1);
                        dicIn.Add("t.SALES_USER_KEY", saleUserkey);
                    }
                    if (!string.IsNullOrEmpty(context.Request["sNAME"]))
                        dicLike.Add("t.CUSTOMER_NAME", context.Request["sNAME"]);
                    result = bo.getCustomer(dicLike, dicEqual, dicIn, pageSize, pageNum);
                    break;
                case "add":
                    //
                    result = bo.addCustomer(context);
                    break;
                case "edit":
                    //编辑群组
                    result = bo.editCustomer(context);
                    break;
                case "del":
                    //删除群组
                    result = bo.delCustomer(context);
                    break;
                case "revert":
                    //还原
                    result = bo.revertCustomer(context);
                    break;

            }
        }
        catch (Exception ex)
        {
            var error = new Entities.Status { Success = false, Message = ex.Message };
            result = error.ToJson();

        }
        finally
        {
            context.Response.Write(result);
        }
    }


}
